program typefun
   open(unit=11, form="formatted", file="lesson3.txt")
   call try_particles
   call try_points
   call try_ucpoints
   call try_curves
end program typefun

subroutine try_particles
   use particles
   implicit none
   type(particle) p
   type(particle):: q = particle("h", & !name
                                 point(0., 1., -1.), & !location
								 point(0., 1., 1.), & !momentum
								 1.02, & ! mass
								 1.0, & !charge
								 325 & !serial number
								 )

   write(11,*) "p "
   write(11,*) p
   write(11,*) "q "
   write(11,*) q
end subroutine try_particles 

subroutine try_points
   use precision
   use points
   implicit none
   type(point), parameter:: origin = point(0.0, 0.0, 0.0)
   type(point), parameter:: e1 = point(1.0, 0.0, 0.0)
   type(point), parameter:: e2 = point(0.0, 1.0, 0.0)
   type(point), parameter:: e3 = point(0.0, 0.0, 1.0)
   type(point) x1, x2
   x1 = 3.0 * e1 + 4.0 * e2 + 5.0 * e3
   x2 = -4.0 * x1 - (2.0_adequate * e2) + e3
   write(11, *) "x1 ", x1
   write(11, *) "x2 ", x2
   write(11, *) "norm(x1)", norm(x1)
   write(11, *) "sqrt(x1)", sqrt(x1)
   write(11, *) "dot product", x1 .dot. x2
end subroutine try_points

subroutine try_ucpoints
   use precision
   use ucpoints
   use points
   implicit none
   type(point) a
   type(ucpoint) r1, r2

   r1 = pi / 4.0_adequate
   r2 = -r1 + pi/12.0_adequate
   write (11, *) "r1 ", x (r1), y (r1), theta (r1)
   write (11, *) "r2 ", x (r2), y (r2), theta (r2)
   write (11, *) "r3 ", theta (as_ucpoint (-0.3 * pi))
   a = point(x(r1), y(r1), 0.0)
   write (11, *) "a ", a
end subroutine try_ucpoints

subroutine try_curves
   use precision
   use curves
   implicit none
   type(curve) c1, c2, c3
   real(adequate) xx(4), yy(4)
   xx = (/ 1., 2., 3., 4. /)
   yy = xx**2 + 1
   call create(c1, xx, yy)
   call create(c2, xx, yy / 2.)
   write(11, *) "y(c2) ", y(c2)
   if(sum(xx) > 2.5) then
      c3 = c2
   endif
   call destroy(c1)
   call destroy(c2)
   call destroy(c3)
end subroutine try_curves